<?
/**
 *  Copyright 2008 Ivan Grosny 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at 
 *  http://www.apache.org/licenses/LICENSE-2.0 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *  @author Ivan Grosny
 */
session_start();

include_once 'config/default.php';

if(isset($_GET['logout']))
{
	session_destroy();
	header("Location: index.php");
}

if(isset($_POST['db_host']))
{
	$_SESSION['db_host'] = $_POST['db_host'];
	$_SESSION['db_user'] = $_POST['db_user'];
	$_SESSION['db_pass'] = $_POST['db_pass'];
	$_SESSION['db_port'] = $_POST['db_port'];
	
	if(trim($_POST['db_name']))
	{
		$_SESSION['db_name'] = $_POST['db_name'];	
	}
	
	if(Db::connect())
		header("Location: app/");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Mywea v.<?= VERSION ?></title>
    <link href="stylesheets/login.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?= Flash::display() ?>
<form action="index.php" method="post">
	<fieldset>
		<legend>Connection configuration</legend>
			<label>
				<span>Host</span>
				<input type="text" name="db_host" id="db_host" value="<?= DB_HOST ?>" />
			</label>
			<label>
				<span>Username</span>
				<input type="text" name="db_user" id="db_user" value="<?= DB_USER ?>" />
			</label>
			<label>
				<span>Password</span>
				<input type="password" name="db_pass" id="db_pass" value="<?= DB_PASS ?>" />
			</label>
			<label>
				<span>Port</span>
				<input type="text" name="db_port" id="db_port" value="<?= DB_PORT ?>" />
			</label>
			<label>
				<span>Default schema</span>
				<input type="text" name="db_name" id="db_name" value="<?= DB_NAME ?>" />
			</label>
			<input type="submit" name="submit" id="connect" value="Connect!" />
	</fieldset>
</form>
</body>
</html>
